<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script type="text/javascript" src="../js/jquery-1.8.0.min.js" ></script>
		<script type="text/javascript" src="../js/head_public.js" ></script>
		<style>
			.baocun{color: #fff;border: 1px solid #fff;background: #ff7e00;position: absolute;z-index: 10;top: 0.12rem;right: 0.2rem;}
		    .xinbie{width: 95%;margin: auto;overflow: hidden;color: #666;}
		    .radio-div img{display: inline-block;width: 0.4rem;}
            .radio-div{padding: 0.3rem 0px;}
            .imgbtn{display: block;float: left;width: 30%;margin-right: 1.5%;}
           
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">委派工单</h1>
		</header>
		<div class="mui-content" >
		    <form class="changep-form" >
		    	<div style="background: #fff;">
		    		<p style="border: none;">
		    			<span>电梯编号：</span>
			    		<select name="bianhao" id="bianhao">
			    			<option  value="">请选择电梯编号</option>
			    		</select>
			    	</p>
		    	</div>
		    	
		    	<!--<div class="kong" ></div>
		    	<div style="background: #fff;">
		    		<p style="border: none;background: #fff;">
			    		<span style="width: 100%;padding-top: 3px;font-size: 0.35rem;">电梯位置</span>
			    		<textarea placeholder="请输入电梯位置" style="display: block;border: none;font-size: 0.35rem;width: 100%;"></textarea>
			    	</p>
		    	</div>-->
		    	<div class="kong" ></div>
		    	<div style="background: #fff;">
		    		<p style="border: none;background: #fff;">
			    		<span style="width: 100%;padding-top: 3px;font-size: 0.35rem;">故障详情：</span>
			    		<textarea placeholder="请输入电梯故障详情" id="reause" style="display: block;border: none;font-size: 0.35rem;width: 100%;"></textarea>
			    	</p>
		    	</div>
			    <div class="kong" ></div>
			    <div style="border: none;background: #fff;padding-bottom: 5px;">
		    		<span style="width: 100%;padding-left: 10px;font-size: 0.35rem;">图片详情</span>
		    		<div style="width: 100%;height: 75px;margin-top: 10px;">
		    			<!--<input type="file"  style="position: absolute;top: 0px;left: 0px;width: 100%;height: 100%;opacity: 0;"/>-->
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="1"/>
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="2"/>
		    			<img src="../images/chuantu.png" height="70" class="imgbtn" num="3"/>
		    			<input type="hidden" class="imginput" />
		    			<input type="hidden" class="imginput" />
		    			<input type="hidden" class="imginput" />
		    		</div>
		    	</div>
		    	<div class="kong"></div>
		    	<div style="background: #fff;">
		    		<p style="border: none;">
			    		<select style="padding: 0px;" id="weibao-person">
			    			<option value="">请选择维保人员</option>
			    		</select>
			    	</p>
		    	</div>
		    	<div class="kong"></div>
		    	<div style="background: #fff;">
		    		<div class="xinbie" style="background: #fff;">
					    <span style="display: block;width: 110px;float: left;padding: 0.3rem 0px;">是否急修:</span>
						<div style="width:180px;overflow: hidden;float: left;padding-left: 50px;">
							<div style="width: 35%;float: left;overflow: hidden;" class="radio-div"  flag="0" value="2">
								<img src="../images/radio-icon.png" />
								<label for="nv">是</label>
							</div>
							<div style="width: 35%;float: left;overflow: hidden;" class="radio-div" flag="0" value="1">
								<img src="../images/radio-icon.png" />
								<label for="nan">否</label>
							</div>
						</div>
				    </div>
		    	</div>
		    	
		    	<div style="background: #efeff4;padding: 2px 0px;">
		        	 <button class="ch-ph-btn" type="button" style="font-weight: bold;letter-spacing: 2px;">委派工单</button>
		        </div>
		    </form>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/session.js"></script>
		<script type="text/javascript">
		mui.init()
			mui(".xinbie").on("tap",".radio-div",function(){
    		if($(this).attr("flag")=="0"){
    			$(this).attr("flag","1");
    			$(this).siblings(".radio-div").attr("flag","0");
    		}else{
    			$(this).attr("flag","0");
    			$(this).siblings(".radio-div").attr("flag","1");
    		}
    		changeYangshi()
    	})
    	function changeYangshi(){
            $(".radio-div").each(function(i){
            	var flag=$(this).attr("flag");
            	if(flag=="1"){
            		$(this).find("img").attr("src","../images/radio-active.png")
            	}else{
            		$(this).find("img").attr("src","../images/radio-icon.png")
            	}
            })
        }
//  	判断登录与否
        var userid=getCookie("userid")
        var work=getCookie("work")
        var work_id=getCookie("workid")      	
		if(userid==null||userid==""){
			alert("您还没有登录，请登录")
			mui.openWindow({url:"login.html"})
		}else{
		 if(work!="1"){
				alert("您不是管理员,您没有权限")
				mui.openWindow({url:"../public/index.html"})
			}
		}
		var data={};
		data.member_id=userid;
		data.member_work=work;
		data.work_id=work_id;
		//获取电梯编号
		$.post(net+"/public/index.php?s=api/elevator/manage_elevator",data,function(res){
			if(res.code=="200"){
				if (res.result!=null&&res.result.length!=0) {
					var str="";
					$.each(res.result,function(index,val){
						str+='<option value="'+this.code+'">'+this.code+'</option>'
					})
				}
				$("#bianhao").append(str)
			}
		})
		//获取维保人员名单
		$.post(net+"/public/index.php?s=api/elevator/select_service/",{member_id:userid},function(res){
			if(res.code=="200"){
				if (res.result!=null&&res.result.length!=0) {
					var str="";
					$.each(res.result,function(index,val){
						str+='<option value="'+this.id+'">'+this.member_truename+'</option>'
					})
				}
				$("#weibao-person").append(str)
			}
		})
		
    	//			图片上传 
			 //扩展API完成后执行的操作
                function plusReady(){               
                 //给选中的li增加判别class
                     mui(".mui-content").on("tap",".imgbtn",function(){
                     	num=$(this).attr("num")
                     	page.imgUp();
                     })  
                } 
                //弹出系统按钮选择框
                var page=null; 
                page={ 
                    imgUp:function(){ 
                        var m=this; 
                       /* console.log(m);*/
                        plus.nativeUI.actionSheet({cancel:"取消",buttons:[ 
                            {title:"拍照"}, 
                            {title:"从相册中选择"} 
                        ]}, function(e){//1 是拍照  2 从相册中选择 
                            switch(e.index){ 
                                case 1:appendByCamera();break; 
                                case 2:appendByGallery();break; 
                            } 
                        }); 
                    } 
                } 
               
            // 拍照添加文件
            function appendByCamera(){
                plus.camera.getCamera().captureImage(function(e){
                    console.log("e is" +  e);
                    plus.io.resolveLocalFileSystemURL(e, function(entry) {
                        var path = entry.toLocalURL();
                    
                        upload(path)
                        
                    }, function(e) {
                        mui.toast("读取拍照文件错误：" + e.message);
                    });      
                });   
            }
            // 从相册添加文件
            function appendByGallery(){
                plus.gallery.pick(function(path){
                
                    upload(path)
                   
                });
            }
             
               
            //服务端接口路径
            var server = net+"/public/index.php?s=api/elevator/service_img_uplode";
            //获取图片元素
            var files = document.getElementById('avatar');
            // 上传文件
            function upload(path){
                var wt=plus.nativeUI.showWaiting();
                var task=plus.uploader.createUpload(server,
                    {method:"POST",
                     member_id:userid
                    },
                    function(t,status){ //上传完成
//                  	alert(JSON.stringify(t))
                        if(status==200){
                            alert("上传成功");
                            var data=$.parseJSON(t.responseText);
                            $(".imgbtn:nth-of-type("+num+")").attr("src",net+data.result+'?timestep='+Math.random())
                            $(".imginput:nth-of-type("+num+")").val(data.result);
                            wt.close(); //关闭等待提示按钮
                        }else{
                            alert("上传失败："+status);
                            wt.close();//关闭等待提示按钮
                        }
                    }
                );  
                //添加其他参数
                
                task.addData("member_id",userid);
                task.addData("num",num);
                task.addData("type","2");
                task.addFile(path,{key:"serviceimg"});
                task.start();
            } 
            //扩展API是否准备好，如果没有准备好则监听plusReady 
            if(window.plus){
                plusReady();
            }else{
                document.addEventListener("plusready",plusReady,false);
            }
            
           mui("form").on("tap",".ch-ph-btn",function(){
           	   var code=$("#bianhao").val();
           	   var reause=$("#reause").val();
           	   var weibao_person=$("#weibao-person").val();
           	   var imgs="";
           	   $(".imginput").each(function(i){
           	   	  if($(this).val()!=""&&$(this).val()!=null){
           	   	  	 imgs+=$(this).val()+","
           	   	  }
           	   })
           	   var special="";
				$(".radio-div").each(function(i){
					if($(this).attr("flag")=="1"){
						special=$(this).attr("value");
					}
				})
           	  if(code==""||code==null){
           	  	alert("请选择电梯编号")
           	  	return false;
           	  }else if(reause==""||reause==null){
           	  	alert("请填写故障详情")
           	  	return false;
           	  }else if(imgs==null||imgs.length==0){
           	  	alert("请上传图片")
           	  	return false;
           	  }else if(weibao_person==""||weibao_person==null){
           	  	alert("请先择维保人员")
           	  	return false;
           	  }else if(special==""||special==null){
           	  	alert("请先择是否急修")
           	  	return false;
           	  }
           	  var params={}
           	  params.member_id=userid;
           	  params.pic=imgs;
           	  params.code=code;
           	  params.reause=reause;
           	  params.userid=weibao_person;
           	  params.special=special;
           	  params.work_id=work_id;
           	   $.post(net+"/public/index.php?s=api/elevator/service_bug_add",params,function(res){
           	   	if(res.code=="200"){
           	   	 	alert("提交成功")
           	   	 	mui.back();
//         	   	 	location.href="weipai_list.html";
           	   	}	 
           	   })
           })
		</script>
	</body>

</html>